<?php
/**
 * NAME: modules_manager
 * WHEN: OnMsg
 * PROVIDES: NONE
 * AUTOLOAD: true
 * DESCRIPTION: Zarządca modułów Tempaka
 * VERSION: 0.1
 * UPDATE: http://update.tempaq2.blacksoft.eu/check.php
 */
  
 exit();
 
//*module_register_start
	$cmd = $module->addCommand('!modules', '_lang_modules_help' , null, true);
	$module->addSubcommand($cmd, 'load', '_lang_load_help', '.+', true);
	$module->addSubcommand($cmd, array('uload', 'unload'), '_lang_unload_help', '.+', true);
	$module->addSubcommand($cmd, 'available', '_lang_available_help', null, true);
	$module->addSubcommand($cmd, 'loaded', '_lang_loaded_help', null, true);
	$module->addSubcommand($cmd, 'delete', '_lang_delete_help', '[^ ]\\.php', true);
	$module->addSubcommand($cmd, 'add', '_lang_add_help' , '([^ ]\\.php) (.+)');
	$cmd2 = $module->addSubcommand($cmd, 'reload', '_lang_reload_help' , null, true);
	$module->addSwitch($cmd2, array('--force', '-f'), '_lang_force_help', null, true);
	
//*function_start
	if (count($parsed_module)) {
		$msg = '';
		foreach ($parsed_module as $k => $v) {
			switch($k) {
				case 1:
					$moduly = explode(' ', $v[0]);
					foreach ($moduly as $x) {
						if ($bot->load_module((isset($bot->modulesinfo[$x])?$bot->modulesinfo[$x]['filename']:$x)))
								$bot->send_text('module_reloaded', $x);
					}
					break;
				case 2:
					$moduly = explode(' ', $v[0]);
					foreach ($moduly as $x) {
						if ($bot->unload_module($x));
							$bot->send_text('module_unloaded', $x);
					}
					break;
				case 3:
					$list = $bot->load_modules($data, 1);
					foreach ($list as $a=>$b) {
						$msg.=$a.', ';
					}
					$msg = $lang->text('available_modules').substr($msg, 0, strlen($msg)-2);
					$bot->send($msg);
					break;
				case 4:
					foreach ($bot->func as $k=>$v) {
							$msg.=$k.', ';
					}
					$msg = $bot->lang->text('loaded_modules').substr($msg, 0, strlen($msg)-2);
					$bot->send($msg);
					$bot->send_text('to_learn_more', '!help');
					break;
				case 5: //usuwanie
					if (file_exists(MODULES_DIR.$v[0].'.deleted')) {
						if (unlink(MODULES_DIR.$v[0].'.deleted')) {
							$bot->send_text('module_deleted_completely');
							break;
						}
						$bot->send_text('error_deleting', $v[0]);
						break;
						
					} else {
						if (file_exists(MODULES_DIR.$v[0])) {
							if (rename(MODULES_DIR.$v[0], MODULES_DIR.$v[0].'.deleted')) {
								$bot->send_text('module_deleted');
								break;
							}
							$bot->send_text('error_deleting', $v[0]);
							break;
						}
					}
					$bot->send_text('delete_not_found', $v[0]);
					break;
				case 6: //dodawanie
					if (!file_exists(MODULES_DIR.dirname($v[1])))
						mkdir(MODULES_DIR.dirname($v[1]));
					if ($bot->isUrl($v[2])) {
						if ($plik = file_get_contents($v[2])) {
							if (file_put_contents(MODULES_DIR.$v[1], $plik)) {
								$bot->send_text('adding_complete');
								break;
							}
							$bot->send_text('adding_error');
							break;
						}
						$bot->send_text('adding_download_error');
						break;
					}
					$bot->send_text('adding_wrong_url');
					break;
				case 7:
					if (!isset($parsed_module[8]))
						$bot->reload_active_modules($data);
					else
						$bot->force_reload();
					$this->send_text('modules_reloaded');
					break;
				case 8: break;
				default:
					$bot->send('Not implemented yet');
			}
		}
	}
?>